<template>
  <div class="photoinfo-container">
    <h3>{{ photoinfo.title }}</h3>
    <p class="subtitle">
      <span>发表时间: {{photoinfo.add_time | dateFormat("YYYY-MM-DD HH:mm:ss")}}</span>
      <span>点击:{{ photoinfo.click }}</span>
    </p>
    <hr>
    <!-- 缩略图 -->
    <div class="thumbs">
      <!-- 注意：这里使用的 vue-preview 组件是版本 1.1.3,
           之前上课录屏时候, 所使用的 1.0.5 版本的 vue-preview 存在 Bug -->
      <vue-preview :slides="list" ></vue-preview>
    </div>

    <div class="content" v-html="photoinfo.content"></div>

    <com-box v-if="photoinfo !== null" :id="id"></com-box>
  </div>
</template>
<script>
import comment from "../subcomponents/comment.vue";
export default {
  data() {
    return {
      id: this.$route.params.id, // 从路由中获取到 图片id
      photoinfo: {}, //图片详情
      list:[]
    };
  },
  created() {
    this.getPhotoInfo();
    this.getThumbs();
  },
  methods: {
    getPhotoInfo() {
      this.$http.get("api/getimageInfo/" + this.id).then(res => {
        if (res.body.status === 0) {
          this.photoinfo = res.body.message[0];
          console.log(this.photoinfo);
        }
      });
    },
    getThumbs() {
      // 获取缩略图
      this.$http.get("api/getthumimages/" + this.id).then(res => {
        if (res.body.status === 0) {
          res.body.message.forEach(item => {
            item.h = 600;
            item.w = 600;
            item.msrc = item.src
          });
          this.list = res.body.message;
        }
      });
    }
  },
  components: {
    "com-box": comment
  }
};
</script>

<style lang="scss" scoped>
.photoinfo-container {
  h3 {
    color: #26a2ff;
    font-size: 16px;
    text-align: center;
    margin: 15px 0;
  }
  .subtitle {
    display: flex;
    justify-content: space-between;
    padding: 0 10px;
    font-size: 13px;
  }
  .content {
    font-size: 12px;
  }
}
</style>

<style lang="scss">
.thumbs {
  width:100%;
  display: flex;
  justify-content: space-between;

  margin: 0 auto;
  .my-gallery {
    display: flex;
    flex-wrap: wrap;
    padding:0 5px;
  }
  figure {
    width: 30%;
    margin: 5px;
    box-shadow: 0 0 8px #999;
    img {
      width: 100%;
      height: 100%;
    }
  }
}
</style>

